package br.facet.pojo;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table (name = "TBL_VENDA")
@SequenceGenerator(name = "seq_venda", sequenceName = "seq_venda", allocationSize = 1)
public class Venda {

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_venda")
	@Column	
	private Integer id;
	
	@ManyToOne(cascade= CascadeType.ALL, fetch= FetchType.EAGER)
	@JoinColumn(name="id_cliente")
	private Cliente cliente;
	
	@OneToMany(mappedBy = "id", targetEntity = Pedido.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "id_venda", insertable = true)
	private List<Pedido> itens;
	
	@Column
	private Date dtVenda;
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	public Date getDtVenda() {
		return dtVenda;
	}

	public void setDtVenda(Date dtVenda) {
		this.dtVenda = dtVenda;
	}

	public List<Pedido> getItens() {
		return itens;
	}

	public void setItens(List<Pedido> itens) {
		this.itens = itens;
	}
}
